package cn.jekun.web.shop.action;

import java.util.List;

import javax.annotation.Resource;

import cn.jekun.component.core.service.gen.DCityService;
import cn.jekun.component.core.service.gen.DProvinceService;
import net.sf.json.JSONArray;

/**
 * 系统参数
 * @author twj
 *
 */
@SuppressWarnings("serial")
public class SysParamAction extends ShopBaseAction{
	@Resource(name = DProvinceService.BEAN_NAME)
	protected DProvinceService provinceService;
	@Resource(name = DCityService.BEAN_NAME)
	protected DCityService cityService;
	/**
	 * 列出所有的省份(仅提供分润模块)
	 * @return
	 */
	public String provinceList(){
		this.resultList = this.provinceService.listBySql("select * from D_PROVINCE",page);
		return "/admin/profit/selectProvince.jsp";
	}
	/**
	 * 列出所有的城市(仅提供分润模块)
	 * @return
	 */
	public String cityList(){
		this.resultList =  this.cityService.listBySql("select * from D_CITY",page);
		return "/admin/profit/selectCity.jsp";
	}
	
	
	
	
	/**
	 * 查找所有的省市
	 * @return json
	 */
	@SuppressWarnings("unchecked")
	public String findAllProvince(){
		List<String> list = this.provinceService.listBySql("select * from D_PROVINCE");
		JSONArray json = JSONArray.fromObject(list);
		return this.writeJson(json);
	}
	/**
	 * 查找省份下面所有的地市
	 * @return json
	 */
	@SuppressWarnings("unchecked")
	public String findCityByProvince(){
		String provinceId = this.request.getParameter("provinceId");
		if(provinceId == null){
			this.saveActionMessage("暂无该省地市信息！");
			return "";
		}else{
		List<String> list = this.cityService.listBySql("select * from D_CITY where PROVINCE_ID='"+provinceId+"'");
		JSONArray json = JSONArray.fromObject(list);
		return this.writeJson(json);
		}
		
	}
	/**
	 * 查找地市下所有的区
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public String findRegionByCity(){
		String cityId = this.request.getParameter("cityId");
		if(cityId == null){
			this.saveActionMessage("暂无该区域信息！");
			return "";
		}else{
		List<String> list = this.cityService.listBySql("select * from D_REGION where CITY_ID='"+cityId+"'");
		JSONArray json = JSONArray.fromObject(list);
		return this.writeJson(json);
		}
	}
	/**
	 * 城市翻译
	 * @return
	 */
	public String cityTranslate(){
		
		return "json";
	}
	/**
	 * 省份翻译
	 * @return
	 */
	public String provinceTranslate(){
		
		return "json";
	}
}
